// 全局request配置

export default {
    common:{
        baseUrl:"http://localhost:3001/api",
        data:{},
        headers:{
            "Content-Type":"application/json",
            "Content-Type":"application/x-www-form-urlencoded"
        },
        method:'POST',
        dataType:'json'
    },
    request(options){
        options.url = this.common.baseUrl + options.url;
        options.data = options.data || this.common.data;
        options.header = options.header || this.common.headers;
        options.method = options.method || this.common.methods;
        options.dataType = options.dataType || this.common.dataType;
        return new Promise((res,rej)=>{
            uni.request({
                ...options,
                success:(result)=>{
                    if(result.statusCode!=200){
                        return rej();
                    }
                    let data = result.data.data;
                    res(data)
                }
            })
        })
    }
}